﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tunnel.Devices.DeviceEntity;
using Tunnel.Plan;
using Tunnel.Tools.FcmsTools;

namespace Tunnel
{
    public partial class testForm : Form
    {
        public testForm()
        {
            InitializeComponent();
        }
        TS tS = new TS();

        private void Button1_Click(object sender, EventArgs e)
        {
            PlanForm f = new PlanForm();
            f.Show();
            
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            while (true)
            {
                if (!string.IsNullOrEmpty(tS.RedId))
                {
                    label1.Text = tS.RedId;
                    break;
                }
            }
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            TimeToRun timeToRun = new TimeToRun();
            timeToRun.StartTimer();
        }

        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            TimeToRun timeToRun = new TimeToRun();
            timeToRun.timer.Start();
        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Button4_Click(object sender, EventArgs e)
        {
            FcmsProtocol fcms = new FcmsProtocol();
            string s = textBox1.Text;
            List<byte> listbyte = Encoding.Default.GetBytes(s).ToList();
            List<List<byte>> commandsList = fcms.GetCommandsList(listbyte, "play.lst");
            fcms.UploadFileByNet("play.lst", listbyte, "", System.Net.IPAddress.Parse("127.0.0.1"), 9527);
            string hexOutput = string.Empty;
            for (int i = 0; i < commandsList[0].Count; i++)
            {
                hexOutput += string.Format("{0:X2}", commandsList[0][i]) + " ";
            }
            string result = hexOutput;
            textBox2.Text = result;
        }
    }
}
